from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout
from qfluentwidgets import CardWidget, BodyLabel, IconWidget, InfoBarIcon, HyperlinkLabel
from PyQt6.QtCore import Qt
import sys

class Example2(CardWidget):
    """卡片"""
    def __init__(self, data, parent=None):
        super().__init__(parent)
        # self.__kick_off_time = BodyLabel(data['kick_off_time'], self)
        # self.__team_a = BodyLabel(data['team_a'], self)
        # self.__team_b = BodyLabel(data['team_b'], self)
        self.setup_ui()

    def setup_ui(self):
        """设置ui"""
        # 创建QGridLayout删格布局
        grid_layout = QGridLayout()
        # 为了使用对应的方法,将引入垂直布局控件放置元素3和元素4
        vertical_layout = QVBoxLayout()
        body_label3 = BodyLabel('元素三 0,2')
        body_label3.setStyleSheet("background-color: lightblue;")
        # grid_layout.addWidget(body_label3, 0, 2, 1, 1)
        vertical_layout.addWidget(body_label3)
        body_label4 = BodyLabel('元素四 1, 2')
        body_label4.setStyleSheet("background-color: lightblue;")
        # grid_layout.addWidget(body_label4, 1, 2, 1, 1)
        vertical_layout.addWidget(body_label4)
        
        grid_layout.addLayout(vertical_layout, 0, 2, 2, 1)

        body_label1 = BodyLabel('元素一 0,0')
        body_label1.setStyleSheet("background-color: lightblue;")
        grid_layout.addWidget(body_label1, 0, 0, 3, 1)
        body_label2 = BodyLabel('元素二 0,1')
        body_label2.setStyleSheet("background-color: lightblue;")
        grid_layout.addWidget(body_label2, 0, 1, 2, 1)
        body_label5 = BodyLabel('元素五 2,1')
        body_label5.setStyleSheet("background-color: lightblue;")
        grid_layout.addWidget(body_label5, 2, 1, -1, -1)

        # 最后，通过setStretch()方法，调整不同行所占空间大小：

        # grid_layout.setRowStretch(0, 1)
        # grid_layout.setRowStretch(1, 3)
        self.setLayout(grid_layout)
        

if __name__ == '__main__':
    data = {
        "kick_off_time": "2022-01-01 12:00:00",
        "league": "西甲",
        "team_a": "皇马",
        "team_b": "巴萨",
        "odd_a": "1.5",
        "odd_b": "2.5",
        "handicap": "3.5",
    }
    app = QApplication(sys.argv)
    window = Example2(data)
    window.setGeometry(100, 100, 300, 300)
    window.setWindowOpacity(0.95)
    window.show()
    sys.exit(app.exec())